package com.soft.javase.ch08.test.test2;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class RemoveDuplicates {
    public static void main(String[] args) {
        // 去除自定义对象(Person)的重复元素
        List<Person> personList = new ArrayList<>();
        personList.add(new Person("Alice", 25));
        personList.add(new Person("Bob", 30));
        personList.add(new Person("Alice", 25));
        personList.add(new Person("Charlie", 35));
        personList.add(new Person("Bob", 30));

        System.out.println("原始Person列表: " + personList);

        Set<Person> personSet = new HashSet<>(personList);
        List<Person> uniquePersonList = new ArrayList<>(personSet);
        System.out.println("去重后的Person列表: " + uniquePersonList);
    }
}
